package view.toolbar
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import style.Filters;
	
	import view.toolbar.event.DiceEvent;

	public class Dice extends Sprite
	{
		private var _ui:UIDice;
		
		private var _canSelected:Boolean = false;
		private var _point:int;
		
		public function Dice()
		{
			createUI();
		}
		
		private function createUI():void
		{
			_ui = new UIDice;
			_ui.stop();
			addChild(_ui);
		}
		
		public function setPoint(value:int):void{
			_point = value;
			_ui.gotoAndStop(value);
		}
		
		public function getPoint():int{
			return _point;
		}
		
		public function gotoGlow():void{
			_ui.filters = [Filters.glowFilter];
		}
		
		public function gotoNormal():void{
			_ui.filters = null;
		}
		
		public function set canSelected(value:Boolean):void{
			_canSelected = value;
			if (_canSelected){
				buttonMode = true;
				addEventListener(MouseEvent.CLICK, onClick);
			}
			else{
				buttonMode = false;
				removeEventListener(MouseEvent.CLICK, onClick);
			}
		}
		
		private function onClick(e:MouseEvent):void{
			var event:DiceEvent = new DiceEvent(DiceEvent.POINT_SELECTED);
			event.point = _point;
			dispatchEvent(event);
			
			gotoGlow();
		}
	}
}